<template>
  <div class="mod-user">
    <el-tabs type="border-card" @tab-click="handleClick">
    <el-tab-pane label="会员活跃度">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item>
          <el-input v-model="dataForm.keywords" placeholder="会员账号、会员名称" clearable style="width:200px"></el-input>
        </el-form-item>
        <el-form-item label="用户类型">
		      <el-select v-model="dataForm.userType" placeholder="用户类型">
		        <el-option label="全部" value="" ></el-option>
            <el-option label="普通联盟店" value="2" ></el-option>
            <el-option label="中级版联盟店" value="5" ></el-option>
            <el-option label="高级版联盟店" value="6" ></el-option>
            <el-option label="城市合伙人联盟店" value="8" ></el-option>
		      </el-select>
	      </el-form-item>
        <el-form-item label="">
		      <el-date-picker
          v-model="dataForm.startTime"
          type="datetime"
          value-format = "yyyy-MM-dd HH:mm:ss"
          placeholder="起始时间">
		      </el-date-picker>
	      </el-form-item>
	      <el-form-item label="">
		      <el-date-picker
          v-model="dataForm.endTime"
          type="datetime"
          value-format = "yyyy-MM-dd HH:mm:ss"
          placeholder="结束时间">
		      </el-date-picker>
	      </el-form-item>
        <el-form-item label="活跃次数">
		      <el-select v-model="dataForm.loginCount" placeholder="活跃次数">
		        <el-option label="倒序" value="0" ></el-option>
            <el-option label="升序" value="1" ></el-option>
		      </el-select>
	      </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()" type="primary" plain>查询</el-button>
          <el-button icon="el-icon-download" type="primary" @click="excel(1)">导出</el-button>
        </el-form-item>
      </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <!-- <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column> -->
      <el-table-column
        prop="userName"
        header-align="center"
        align="center"
        label="会员账号">
      </el-table-column>
      <el-table-column
        prop="trueName"
        header-align="center"
        align="center"
        label="会员名称">
      </el-table-column>
      <el-table-column
        prop="userType"
        header-align="center"
        align="center"
        label="会员类型">
        <template slot-scope="scope">
            <p v-if="scope.row.userType == 1"> 区域运营商</p>
            <p v-else-if ="scope.row.userType == 2">普通联盟店</p>
            <p v-else-if ="scope.row.userType == 3">消费者</p>
            <p v-else-if ="scope.row.userType == 4">VIP会员</p>
            <p v-else-if ="scope.row.userType == 5">中级版联盟店</p>
            <p v-else-if ="scope.row.userType == 6">高级版联盟店</p>
            <p v-else-if ="scope.row.userType == 7">城市合伙人</p>
            <p v-else-if ="scope.row.userType == 8">城市合伙人联盟店</p>
          </template>
      </el-table-column>
      <el-table-column
        prop="loginCount"
        header-align="center"
        align="center"
        label="活跃次数">
      </el-table-column>
      <el-table-column
        prop="address"
        header-align="center"
        align="center"
        label="最后登录地点">
      </el-table-column>
      <el-table-column
        prop="lastLoginDate"
        header-align="center"
        align="center"
        label="最后登录时间">
      </el-table-column>
      <el-table-column
        prop="payAmountOfMoney"
        header-align="center"
        align="center"
        label="最近一笔交易金额">
        <template slot-scope="scope">
          <span v-if="scope.row.payAmountOfMoney != null">￥ {{scope.row.payAmountOfMoney}}</span>
          <span v-if="scope.row.payAmountOfMoney == null">￥ 0</span>
        </template>
      </el-table-column>
      <el-table-column
        prop="payDate"
        header-align="center"
        align="center"
        label="最近一笔交易时间">
      </el-table-column>
      <el-table-column
        prop="payType"
        header-align="center"
        align="center"
        label="交易类型">
      </el-table-column>
    </el-table>
    </el-tab-pane>
    <el-tab-pane label="商城订单分析">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item>
          <el-input v-model="dataForm.keywords" placeholder="会员账号、会员名称" clearable style="width:200px"></el-input>
        </el-form-item>
        <el-form-item label="用户类型">
		      <el-select v-model="dataForm.userType" placeholder="用户类型">
		        <el-option label="全部" value="" ></el-option>
            <el-option label="普通联盟店" value="2" ></el-option>
            <el-option label="中级版联盟店" value="5" ></el-option>
            <el-option label="高级版联盟店" value="6" ></el-option>
            <el-option label="城市合伙人联盟店" value="8" ></el-option>
		      </el-select>
	      </el-form-item>
        <el-form-item label="排序类型">
		      <el-select v-model="dataForm.type" placeholder="排序类型">
		        <el-option label="默认" value="0"></el-option>
            <el-option label="周订单" value="1"></el-option>
            <el-option label="周消费" value="2"></el-option>
            <el-option label="月下单" value="3"></el-option>
            <el-option label="月消费" value="4"></el-option>
            <el-option label="总订单" value="5"></el-option>
            <el-option label="总消费" value="6"></el-option>
		      </el-select>
	      </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()" type="primary" plain>查询</el-button>
          <el-button icon="el-icon-download" type="primary" @click="excel(2)">导出</el-button>
        </el-form-item>
      </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <!-- <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column> -->
      <el-table-column
        prop="userName"
        header-align="center"
        align="center"
        label="会员账号">
      </el-table-column>
      <el-table-column
        prop="trueName"
        header-align="center"
        align="center"
        label="会员名称">
      </el-table-column>
      <el-table-column
        prop="userType"
        header-align="center"
        align="center"
        label="会员类型">
        <template slot-scope="scope">
            <p v-if="scope.row.userType == 1"> 区域运营商</p>
            <p v-else-if ="scope.row.userType == 2">普通联盟店</p>
            <p v-else-if ="scope.row.userType == 3">消费者</p>
            <p v-else-if ="scope.row.userType == 4">VIP会员</p>
            <p v-else-if ="scope.row.userType == 5">中级版联盟店</p>
            <p v-else-if ="scope.row.userType == 6">高级版联盟店</p>
            <p v-else-if ="scope.row.userType == 7">城市合伙人</p>
            <p v-else-if ="scope.row.userType == 8">城市合伙人联盟店</p>
          </template>
      </el-table-column>
      <el-table-column
        prop="weeklyOrder"
        header-align="center"
        align="center"
        label="周下单">
        <template slot-scope="scope">
          {{scope.row.weeklyOrder === null ? 0 : scope.row.weeklyOrder}}
        </template>
      </el-table-column>
      <el-table-column
        prop="totalWeeklyAmount"
        header-align="center"
        align="center"
        label="周消费">
        <template slot-scope="scope">
          {{scope.row.totalWeeklyAmount === null ? 0 : scope.row.totalWeeklyAmount}}
        </template>
      </el-table-column>
      <el-table-column
        prop="monthlyOrder"
        header-align="center"
        align="center"
        label="月下单">
        <template slot-scope="scope">
          {{scope.row.monthlyOrder === null ? 0 : scope.row.monthlyOrder}}
        </template>
      </el-table-column>
      <el-table-column
        prop="totalMonthAmount"
        header-align="center"
        align="center"
        label="月消费">
        <template slot-scope="scope">
          {{scope.row.totalMonthAmount === null ? 0 : scope.row.totalMonthAmount}}
        </template>
      </el-table-column>
      <el-table-column
        prop="totalOrder"
        header-align="center"
        align="center"
        label="总订单">
      </el-table-column>
      <el-table-column
        prop="totalConsumptionAmount"
        header-align="center"
        align="center"
        label="总消费">
        <template slot-scope="scope">
          {{scope.row.totalConsumptionAmount === null ? 0 : scope.row.totalConsumptionAmount}}
        </template>
      </el-table-column>
    </el-table>
    </el-tab-pane>
    <el-tab-pane label="联盟店订单分析">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()">
        <el-form-item>
          <el-input v-model="dataForm.keywords" placeholder="会员账号、会员名称" clearable style="width:200px"></el-input>
        </el-form-item>
        <el-form-item label="用户类型">
		      <el-select v-model="dataForm.userType" placeholder="用户类型">
		        <el-option label="全部" value="" ></el-option>
            <el-option label="普通联盟店" value="2" ></el-option>
            <el-option label="中级版联盟店" value="5" ></el-option>
            <el-option label="高级版联盟店" value="6" ></el-option>
            <el-option label="城市合伙人联盟店" value="8" ></el-option>
		      </el-select>
	      </el-form-item>
        <el-form-item label="排序类型">
		      <el-select v-model="dataForm.type" placeholder="排序类型">
		        <el-option label="默认" value="0" ></el-option>
            <el-option label="总流水" value="1" ></el-option>
            <el-option label="总收益" value="2" ></el-option>
		      </el-select>
	      </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()" type="primary" plain>查询</el-button>
          <el-button icon="el-icon-download" type="primary" @click="excel(3)">导出</el-button>
        </el-form-item>
      </el-form>
    <el-table
      :data="dataList"
      border
      v-loading="dataListLoading"
      @selection-change="selectionChangeHandle"
      style="width: 100%;">
      <!-- <el-table-column
        type="selection"
        header-align="center"
        align="center"
        width="50">
      </el-table-column> -->
      <el-table-column
        prop="userName"
        header-align="center"
        align="center"
        label="会员账号">
      </el-table-column>
      <el-table-column
        prop="trueName"
        header-align="center"
        align="center"
        label="会员名称">
      </el-table-column>
      <el-table-column
        prop="userType"
        header-align="center"
        align="center"
        label="会员类型">
        <template slot-scope="scope">
            <p v-if="scope.row.userType == 1"> 区域运营商</p>
            <p v-else-if ="scope.row.userType == 2">普通联盟店</p>
            <p v-else-if ="scope.row.userType == 3">消费者</p>
            <p v-else-if ="scope.row.userType == 4">VIP会员</p>
            <p v-else-if ="scope.row.userType == 5">中级版联盟店</p>
            <p v-else-if ="scope.row.userType == 6">高级版联盟店</p>
            <p v-else-if ="scope.row.userType == 7">城市合伙人</p>
            <p v-else-if ="scope.row.userType == 8">城市合伙人联盟店</p>
          </template>
      </el-table-column>
      <el-table-column
        prop="weeklyOrder"
        header-align="center"
        align="center"
        label="周订单">
      </el-table-column>
      <el-table-column
        prop="monthlyOrder"
        header-align="center"
        align="center"
        label="月下单">
      </el-table-column>
      <el-table-column
        prop="orderTotalNum"
        header-align="center"
        align="center"
        label="总订单">
      </el-table-column>
      <el-table-column
        prop="profit"
        header-align="center"
        align="center"
        label="商家总收益">
      </el-table-column>
      <el-table-column
        prop="flowingWater"
        header-align="center"
        align="center"
        label="订单总流水">
      </el-table-column>
    </el-table>
    </el-tab-pane>
    </el-tabs>
    <el-pagination
      @size-change="sizeChangeHandle"
      @current-change="currentChangeHandle"
      :current-page="pageIndex"
      :page-sizes="[10, 20, 50, 100]"
      :page-size="pageSize"
      :total="totalPage"
      layout="total, sizes, prev, pager, next, jumper">
    </el-pagination>
  </div>
</template>

<script>
export default {
  data () {
    return {
      dataForm: {
        keywords: '',
        userType: '',
        type: '',
        loginCount: '',
        startTime: '',
        endTime: ''
      },
      index: '',
      dataList: [],
      pageIndex: 1,
      pageSize: 10,
      totalPage: 0,
      dataListSelections: [],
      dataListLoading: false
    }
  },
  activated () {
    this.getDataList()
  },
  methods: {
    handleClick (tab, event) {
      this.index = tab.index
      this.dataForm.keywords = ''
      this.dataForm.userType = ''
      this.dataForm.type = ''
      this.dataForm.loginCount = ''
      this.dataForm.startTime = ''
      this.dataForm.endTime = ''
      this.getDataList()
      console.log(tab, event)
    },
    // 获取数据列表
    getDataList () {
      this.dataListLoading = true
      if (this.index === '' || this.index === '0') {
        this.$http({
          url: this.$http.adornUrl('/analysis/queryMembershipActivityList'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'keywords': this.dataForm.keywords,
            'userType': this.dataForm.userType
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.data.list
            this.totalPage = data.data.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      }
      if (this.index === '1') {
        this.$http({
          url: this.$http.adornUrl('/analysis/queryGoodsAnalysisList'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'keywords': this.dataForm.keywords,
            'userType': this.dataForm.userType,
            'type': this.dataForm.type
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.data.list
            this.totalPage = data.data.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      }
      if (this.index === '2') {
        this.$http({
          url: this.$http.adornUrl('/analysis/queryBusinessAnalysisList'),
          method: 'get',
          params: this.$http.adornParams({
            'page': this.pageIndex,
            'limit': this.pageSize,
            'keywords': this.dataForm.keywords,
            'userType': this.dataForm.userType,
            'type': this.dataForm.type
          })
        }).then(({data}) => {
          if (data && data.code === 0) {
            this.dataList = data.data.list
            this.totalPage = data.data.totalCount
          } else {
            this.dataList = []
            this.totalPage = 0
          }
          this.dataListLoading = false
        })
      }
    },
    // 每页数
    sizeChangeHandle (val) {
      this.pageSize = val
      this.pageIndex = 1
      this.getDataList()
    },
    // 当前页
    currentChangeHandle (val) {
      this.pageIndex = val
      this.getDataList()
    },
    // 多选
    selectionChangeHandle (val) {
      this.dataListSelections = val
    },
    // 新增 / 修改
    addOrUpdateHandle (id) {
      this.addOrUpdateVisible = true
      this.$nextTick(() => {
        this.$refs.addOrUpdate.init(id)
      })
    },
    excel (type) {
      if (type === 1) {
        window.location.href = this.$http.adornUrl(`/analysis/membershipActivityListExcel?token=${this.$cookie.get('token')}&userType=${this.dataForm.userType}&startTime=${this.dataForm.startTime}&endTime=${this.dataForm.endTime}&keywords=${this.dataForm.keywords}`)
      }
      if (type === 2) {
        window.location.href = this.$http.adornUrl(`/analysis/orderAnalysisOfMallExcel?token=${this.$cookie.get('token')}&userType=${this.dataForm.userType}&keywords=${this.dataForm.keywords}&type=${this.dataForm.type}`)
      }
      if (type === 3) {
        window.location.href = this.$http.adornUrl(`/analysis/orderAnalysisOfAllianceStores?token=${this.$cookie.get('token')}&userType=${this.dataForm.userType}&keywords=${this.dataForm.keywords}&type=${this.dataForm.type}`)
      }
    }
  }
}
</script>
